package cn.wangsy.zhidao.p20170407.game.jkl;

import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class GamePanel extends JPanel implements KeyListener{
	Person person;
	GamePanel(){
		person = new Person(3,3);
	}
	@Override
	public void paint(Graphics g) {
		super.paint(g); 
		person.draw(g, this);
		this.requestFocus();
		this.addKeyListener(this);
	}
	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void keyPressed(KeyEvent e) {
		
		int keycode = e.getKeyCode();
		if(keycode == KeyEvent.VK_LEFT){
				person.move(1);
		}else if(keycode == KeyEvent.VK_RIGHT){
				person.move(2);
			
		}else if(keycode == KeyEvent.VK_UP){
				person.move(3);
		}else if(keycode == KeyEvent.VK_DOWN){
				person.move(4);
		}
		
		this.repaint();
	}
	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
}
